
package processors;

import containers.Groups;
import containers.TestsTaken;
import java.util.LinkedList;
import readers.QueryStringHandler;
import readers.UserReader;

/**
 * Returns the tests that an user has taken
 * @author Chris
 */
public class processorTakenQuizzes extends processor {
    private String _errMsg;
    processorTakenQuizzes(String query) {
        super(query);
        _errMsg = "[ERROR]";
    }
    
    @Override
    String process() {
        QueryStringHandler qsh = new QueryStringHandler(_queryString);
        String userName = qsh.getElement("username");
        
        if(userName == null) {
            return _errMsg;
        }
        LinkedList<TestsTaken> taken = new LinkedList<TestsTaken>();

        UserReader.getTakenTests(userName, taken);
        
        TestsTaken tt;
        
        //Use to be in xml form but easy to process in space deliminated
        String result = "";//<quizList>";
        while(!taken.isEmpty()) {
            tt = taken.getFirst();
            
            result += tt.teacher + "_" + 
                      tt.group + " " +
                      tt.test + "\n";
                    //"<quiz><teacher>" + tt.teacher + "</teacher>" +
                    //"<group>" + tt.group + "</group>" +
                    //"<test>" + tt.test + "</group>" +
                    //"<score>" + tt.score + "/score>" +
                    //"<expires>0</expires></quiz>";
            
            taken.removeLast();           
        }
        
        result += "";//"</quizList>";
        
        return result;
    }
}
